<template>
  <div class="classes">
    <div class="elmain-container">
      <div class="classType" @mouseover="showRankcontent" @mouseout="hiddenRankcontent">
        <div v-for="(item,index) in classType" :key="index" class="class-rank">
          <div class="classType-title">
            <div class="classType-titlewrapper">
              <span>{{item.name}}</span>
              <span class="iconfont">&#xe633;</span>
            </div>
          </div>
          <div class="clickwrapper" :id="item.id"></div>
        </div>
      </div>
      <div class="block">
        <el-carousel height="376px">
          <el-carousel-item v-for="(item,index) in banner" :key="index">
            <el-image :src="item.src"></el-image>
          </el-carousel-item>
        </el-carousel>
      </div>
      <transition-group name="classTypeFade">
        <div v-for="(item,index) in classType" :key="item.id"
          @mouseover="showcontent(index)"
          @mouseout="hiddenRankcontent"
          class="classType-content-wrapper"
          v-show="showclasscontent==item.id">
            <div class="classType-content-title">
              <span>{{item.name}}</span>
            </div>
            <div class="classType-content-content">
              <a v-for="(content,index) in item.windowContent" :key="index">{{content.name}}</a>
            </div>
        </div>
      </transition-group>

    </div>
  </div>
</template>

<script>
export default {
  name: 'classes',
  data () {
    return {
      showclasscontent: 0,
      banner: [
        {
          src: 'https://i.loli.net/2019/12/24/EuGUzSVvMfrAdIq.png'
        },
        {
          src: 'https://i.loli.net/2019/12/24/umeioLzG3KVqxFw.png'
        }
      ],
      classType: [
        {
          id: 1,
          name: '日语一级',
          windowContent: [
            {
              name: '日语一级旅游',
              src: '/'
            },
            {
              name: '日语一级杂志',
              src: '/'
            },
            {
              name: '鲤鱼旗',
              src: '/'
            }
          ]
        },
        {
          id: 2,
          name: '日语二级',
          windowContent: [
            {
              name: '日语二级旅游',
              src: '/'
            },
            {
              name: '日语二级杂志',
              src: '/'
            },
            {
              name: '日语二级鲤鱼旗',
              src: '/'
            }
          ]
        },
        {
          id: 3,
          name: '日语三级',
          windowContent: [
            {
              name: '日语三级旅游',
              src: '/'
            },
            {
              name: '日语三级杂志',
              src: '/'
            },
            {
              name: '日语三级鲤鱼旗',
              src: '/'
            }
          ]
        }
      ]
    }
  },
  methods: {

    showcontent (index) {
      this.showclasscontent = index + 1
    },
    showRankcontent (event) {
      let timeout
      var that = this
      var control = function () {
        if (timeout) {
          clearTimeout(timeout)
          timeout = null
        }
        timeout = setTimeout(() => {
          that.showclasscontent = event.target.id

          console.log(event.target.id)
        }, 300)
      }
      control()
    },
    hiddenRankcontent () {
      this.showclasscontent = 0
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='scss' scoped>
$headheight: 1.6rem;
.classes {
  display: flex;
  padding: 0 50px;
  min-width: 1152px;
  justify-content: center;
  margin-top: 0.5rem;
}
.classType {
  width: 20%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  color: rgba(255, 255, 255, 0.6);
  padding: 10px 0;
  z-index: 5;
}
.elmain-container {
  width:1152px;
  height: auto;
  margin:0 auto;
  border-radius: 8px;
  box-shadow: 0 12px 24px 0 rgba(7, 17, 27, 0.2);
  background: #2b333b;
  display: flex;
  overflow: hidden;
  position: relative;
}
.elmain-container > .block {
  flex: 1;
}
.el-image {
  height: 100%;
}
.classType > .class-rank {
  width: 100%;
  height: 33.33%;
  font-size: 18px;
  position: relative;
}
.classType-content-wrapper{
  position: absolute;
  top: 0;
  left: 20%;
  width: 9rem;
  height: 6.5rem;
  background:#fff;
  z-index: 3;
  padding: .5rem;
  font-size: 18px;
  font-family: "\9ED1\4F53";
  line-height: 1rem;
  text-align: left;
  font-weight: bolder;
}

.classType-title {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
}
.classType-titlewrapper {
  height: 100%;
  width: 92%;
  margin-left: 10%;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.classType-titlewrapper:hover {
  color: red;
  background: #eee;
}
.classType-content-content {
  width: 95%;
  height: auto;
  font-weight: 400;
  display: flex;
  flex-wrap: wrap;
}
.classType-content-content a {
  margin-right: 0.5rem;
  display: block;
}
.clickwrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.classTypeFade-enter-active,.classTypeFade-leave-active {
  transition: all .6s ease-in-out;
}
.classTypeFade-enter,.classTypeFade-leave-to{
  opacity: 0;
}
.classTypeFade-enter-to ,.classTypeFade-leave{
  opacity: 1;
}
</style>
